<?php

if( !defined('IN_SEC') ){
	exit('Access Denied.');
}

class memcached{
	var $instance = null;
	public function __construct(){
		if ( !class_exists('Memcache', false) ){
			$bug = new Bug();
			$bug->system('Memcache Not Exists[0x00000809x0]');
		}
		$this->instance = new Memcache();
		$config = &conf('cache');
		$connect = $this->instance->connect($config['memcache'], 11211);
		if ( !$connect ){
			$bug = new Bug();
			$bug->system('Memcache Connect Error[0x00000489x0]');
		}
	}

	public function set($key, $val, $flag, $expire){
		return $this->instance->set($key, $val, $flag, $expire);
	}

	public function add($key, $val, $flag, $expire){
		return $this->instance->add($key, $val, $flag, $expire);
	}

	public function get($key = '', $flag = 0){
		return $this->instance->get($key, $flag);
	}

	public function del($key){
		return $this->instance->delete($key, 0);
	}

	public function flush(){
		return $this->instance->flush();
	}

	public function __destruct(){
		$this->instance->close();
		$this->instance = null;
	}

}
